home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / EXAMPLES / IDRAW / LIST.H < prev    next >
C/C++ Source or Header  |  1980-01-05  |  4KB  |  141 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. // $Header: list.h,v 1.9 89/10/09 14:48:35 linton Exp $
  24. // declares classes BaseNode and BaseList.
  25.  
  26. #ifndef list_h
  27. #define list_h
  28.  
  29. #include <InterViews/defs.h>
  30.  
  31. // A BaseNode contains links to its previous and next BaseNodes.
  32. // BaseLists can link BaseNodes to each other to form lists of
  33. // BaseNodes.
  34.  
  35. class BaseNode {
  36.  
  37.     friend class BaseList;
  38.  
  39. public:
  40.  
  41.     BaseNode();
  42.     virtual ~BaseNode();
  43.  
  44.     virtual boolean SameValueAs(void*);
  45.  
  46. protected:
  47.  
  48. private:
  49.  
  50.     BaseNode* prev;        // points to previous BaseNode in list
  51.     BaseNode* next;        // points to next BaseNode in list
  52.  
  53. };
  54.  
  55. // A BaseList maintains and iterates through a list of BaseNodes.
  56.  
  57. class BaseList {
  58. public:
  59.  
  60.     BaseList();
  61.     ~BaseList();
  62.  
  63.     int Size();
  64.     boolean AtEnd();
  65.     BaseNode* First();
  66.     BaseNode* Last();
  67.     BaseNode* Prev();
  68.     BaseNode* Next();
  69.     BaseNode* GetCur();
  70.     BaseNode* Index(int);
  71.     boolean Find(void*);
  72.  
  73.     void Append(BaseNode*);
  74.     void Prepend(BaseNode*);
  75.     void InsertAfterCur(BaseNode*);
  76.     void InsertBeforeCur(BaseNode*);
  77.  
  78.     void RemoveCur();
  79.     void DeleteCur();
  80.     void DeleteAll();
  81.  
  82. private:
  83.  
  84.     BaseNode* head;        // points to dummy head of circular list
  85.     BaseNode* cur;        // points to current node of circular list
  86.     int size;            // stores number of non-dummy nodes in list
  87.  
  88. };
  89.  
  90. // Size returns the number of non-dummy nodes in a list.
  91.  
  92. inline int BaseList::Size () {
  93.     return size;
  94. }
  95.  
  96. // AtEnd returns true if the current node is the dummy node.
  97.  
  98. inline boolean BaseList::AtEnd () {
  99.     return cur == head;
  100. }
  101.  
  102. // First returns the first node in a list (or the head if it's empty)
  103. // and sets the current node to that node.
  104.  
  105. inline BaseNode* BaseList::First () {
  106.     cur = head->next;
  107.     return cur;
  108. }
  109.  
  110. // Last returns the last node in a list (or the head if it's empty)
  111. // and sets the current node to that node.
  112.  
  113. inline BaseNode* BaseList::Last () {
  114.     cur = head->prev;
  115.     return cur;
  116. }
  117.  
  118. // Prev returns the node before the current node and sets the current
  119. // node to that node.
  120.  
  121. inline BaseNode* BaseList::Prev () {
  122.     cur = cur->prev;
  123.     return cur;
  124. }
  125.  
  126. // Next returns the node after the current node and sets the current
  127. // node to that node.
  128.  
  129. inline BaseNode* BaseList::Next () {
  130.     cur = cur->next;
  131.     return cur;
  132. }
  133.  
  134. // GetCur returns the current node in a list.
  135.  
  136. inline BaseNode* BaseList::GetCur () {
  137.     return cur;
  138. }
  139.  
  140. #endif
  141.